﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <title>小知识</title>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="assets/common/i/favicon.ico"/>
    <meta name="apple-mobile-web-app-title" content="小知识"/>
    <link rel="stylesheet" href="Css/amazeui.min.css"/>
    <link rel="stylesheet" href="Css/app.css"/>
    <script src="Scripts/api.js"></script>
    <link rel="stylesheet" href="Css/font_783249_3hfdb7m5w0j.css">
    <script src="Scripts/jquery.min.js"></script>
    <script src="Scripts/font_783249_e5yrsf08rap.js"></script>
    <script>
        BASE_URL = 'https://demo.yiovo.com/';
        STORE_URL = 'index.php?s=/store';
    </script>
</head>

<body data-type="">
<div class="am-g tpl-g">

    <!-- 内容区域 start -->
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-cf">展示的小知识</div>
                </div>
                <div class="widget-body am-fr">
                    <!-- 工具栏 -->
                    <div class="page_toolbar am-margin-bottom-xs am-cf">
                        <form class="toolbar-form" action="">
                            <input type="hidden" name="s" value="/store/goods/index">
                            <div class="am-u-sm-12 am-u-md-3" >
                                <div class="am-form-group" id ="topsetting">
                                    <div class="am-btn-group am-btn-group-xs">
                                        <a class="am-btn am-btn-default am-btn-success"
                                           href="/admin/addNewKnowledge.html">
                                            新增
                                        </a>
                                    </div>
                                </div>
                            </div>
                            <div class="am-u-sm-12 am-u-md-9">
                                <div class="am fr">
                                    <div class="am-form-group am-fl">
                                        <div class="am-input-group am-input-group-sm tpl-form-border-form">
                                            <input type="text" class="am-form-field" name="knowledge_name"
                                                   placeholder="请输入小知识标题"
                                                   value="">
                                            <div class="am-input-group-btn">
                                                <button class="am-btn"
                                                        type="submit">搜索</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>

                    <div class="am-scrollable-horizontal am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped
                         tpl-table-black am-text-nowrap">
                            <thead>
                            <tr>
                                <th>小知识ID</th>
                                <th>小知识图片</th>
                                <th>小知识标题</th>
                                <th>添加时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id = "knowledgeList">
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr"> </div>
                        <div class="am-fr pagination-total am-margin-right">
                        </div>
                    </div>
                    <div id  ="pageitem" class="am-u-lg-12 am-cf">

                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 内容区域 end -->

</div>

<script>

    var isFind = false;
    var getParam = function(name){
        var search = document.location.search;
        var pattern = new RegExp("[?&]"+name+"\=([^&]+)", "g");
        var matcher = pattern.exec(search);
        var items = null;
        if(null != matcher){
            try{
                items = decodeURIComponent(decodeURIComponent(matcher[1]));
            }catch(e){
                try{
                    items = decodeURIComponent(matcher[1]);
                }catch(e){
                    items = matcher[1];
                }
            }
        }
        return items;
    };
    var pagenum = getParam('pagenum');
    var knowledgename = getParam('knowledge_name');

    if(pagenum==null)
        pagenum = 1;

    var ImagePath = null;
    var callbackImage =  function (wxhelpdata) {
        ImagePath = wxhelpdata;
    };
    var addImage =function (kid) {
        document.getElementById('imageimg'+kid).src =  ImagePath;
        document.getElementById('imagehref'+kid).href = ImagePath;
        ImagePath = null;
    };


    if(knowledgename!=null)
    {

        var tophtml="<div class=\"am-btn-group am-btn-group-xs\">\n" +
            "                                                <a class=\"am-btn am-btn-default am-btn-success\"\n" +
            "                                                   href=\"/admin/knowledge.html\">\n" +
            "                                                    返回\n" +
            "                                                </a>\n" +
            "                                            </div>";
        $("#topsetting").append(tophtml);


        var recallfindAllTitleDesc=function (wxhelpdata) {

            for(var n=0;n<wxhelpdata['rows'].length;n++)
            {
                var hid = wxhelpdata['rows'][n]['id'];
                var htitle = wxhelpdata['rows'][n]['title'];
                var hcreate_time = wxhelpdata['rows'][n]['createTime'];
                var htime = dateToStr(new Date(hcreate_time));
                var imagepath = null;
                var tmep_html = "<tr class=\"knowledgeItem"+hid+"\">";
                tmep_html+="<td class=\"am-text-middle\">"+hid+"</td>";
                tmep_html+=" <td class=\"am-text-middle\">";
                tmep_html+="<a id=\"imagehref"+hid+"\" href=\"\"\n" +
                    "title=\"点击查看大图\" target=\"_blank\">";//图片处理
                tmep_html+="<img id=\"imageimg"+hid+"\" src=\"\"\n" +
                    "                                                     width=\"50\" height=\"50\" alt=\"小知识图片\">";
                tmep_html+="</a>\n" +
                    "                                        </td>";
                tmep_html+="<td class=\"am-text-middle\">\n" +
                    "                                            <p class=\"item-title\">"+htitle+"</p>\n" +
                    "                                        </td>"
                tmep_html+="<td class=\"am-text-middle\">"+htime+"</td>";
                tmep_html+="<td class=\"am-text-middle\">\n" +
                    "                                            <div class=\"tpl-table-black-operation\">\n" +
                    "                                                <a href=\"/admin/addNewKnowledge.html?id="+hid+"\" >编辑\n" +
                    "                                                </a>\n" +
                    "                                                <a href=\"javascript:deleteItem("+hid+");\" id=\"item-delete\" class=\"item-delete tpl-table-black-operation-del\"\n" +
                    "                                                   data-id=\""+hid+"\">\n" +
                    "                                                    删除\n" +
                    "                                                </a>\n" +
                    "                                            </div>\n" +
                    "                                        </td>\n" +
                    "                                    </tr>";
                $("#knowledgeList").append(tmep_html);
                getKnowledgeImage(hid,callbackImage);
                addImage(hid);
            }
            var allnum = parseInt(wxhelpdata['total']);
            var pageallnum = parseInt(Math.ceil(allnum/10));
            pagenum = parseInt(pagenum);

            var pagehtml = "<div class=\"am-fr\">\n" +
                "                            <ul class=\"pagination\">";
            if(pagenum==1){
                pagehtml+="<li class=\"disabled\">\n" +
                    "                                    <span>«</span>\n" +
                    "                                </li>\n" +
                    "                                <li class=\"active\">\n" +
                    "                                    <span>1</span>\n" +
                    "                                </li>";
            }
            else if(pagenum<=5){
                pagehtml+="<li><a href=\"/admin/knowledge.html?knowledge_name="+knowledgename+"&pagenum="+(pagenum-1)+"\""+">«</a>\n" +
                    "                                </li>";
                for(var i=1;i<pagenum;i++){
                    pagehtml+="<li><a href=\"/admin/knowledge.html?knowledge_name="+knowledgename+"&pagenum="+i+"\""+">"+i+"</a>\n" +
                        "                                </li>";
                }
                pagehtml+="<li class=\"active\">\n" +
                    "                                    <span>"+pagenum+"</span>\n" +
                    "                                </li>";
            }
            else{
                pagehtml+="<li><a href=\"/admin/knowledge.html?knowledge_name="+knowledgename+"&pagenum="+(pagenum-1)+"\""+">«</a>\n" +
                    "                                </li>";
                pagehtml+="<li><a href=\"/admin/knowledge.html?knowledge_name="+knowledgename+"&pagenum=1\""+">1</a>\n" +
                    "                                </li>";
                pagehtml+="<li class=\"disabled\"><span>...</span>\n" +
                    "                                </li>";
                for(var i=pagenum-3;i<pagenum;i++){
                    pagehtml+="<li><a href=\"/admin/knowledge.html?knowledge_name="+knowledgename+"&pagenum="+i+"\""+">"+i+"</a>\n" +
                        "                                </li>";
                }
                pagehtml+="<li class=\"active\">\n" +
                    "                                    <span>"+pagenum+"</span>\n" +
                    "                                </li>";
            }

            if(pagenum == pageallnum){
                pagehtml+="<li class=\"disabled\">\n" +
                    "                                    <span>»</span>\n" +
                    "                                </li>";
            }
            else if(pageallnum-4<pagenum){

                for(var i=pagenum+1;i<=pageallnum;i++){
                    pagehtml+="<li><a href=\"/admin/knowledge.html?knowledge_name="+knowledgename+"&pagenum="+i+"\""+">"+i+"</a>\n" +
                        "                                </li>";
                }
                pagehtml+="<li><a href=\"/admin/knowledge.html?knowledge_name="+knowledgename+"&pagenum="+(pagenum+1)+"\""+">»</a>\n" +
                    "                                </li>";

            }
            else{
                for(var i=pagenum+1;i<=pagenum+3;i++){
                    pagehtml+="<li><a href=\"/admin/knowledge.html?knowledge_name="+knowledgename+"&pagenum="+i+"\""+">"+i+"</a>\n" +
                        "                                </li>";
                }
                pagehtml+="<li class=\"disabled\"><span>...</span>\n" +
                    "                                </li>";

                pagehtml+="<li><a href=\"/admin/knowledge.html?knowledge_name="+knowledgename+"&pagenum="+pageallnum+"\""+">"+pageallnum+"</a>\n" +
                    "                                </li>";
                pagehtml+="<li><a href=\"/admin/knowledge.html?knowledge_name="+knowledgename+"&pagenum="+(pagenum+1)+"\""+">»</a>\n" +
                    "                                </li>";
            }
            pagehtml+="</ul>\n" +
                "                        </div>\n" +
                "                        <div class=\"am-fr pagination-total am-margin-right\">\n" +
                "                            <div class=\"am-vertical-align-middle\">总记录："+allnum+"</div>\n" +
                "                        </div>";
            $("#pageitem").append(pagehtml);




        };

        findAllKnowledge(knowledgename,1,pagenum,recallfindAllTitleDesc);

    }
    else{

        var callbackCreateTimeDESC = function (wxhelpdata) {
            for(var n=0;n<wxhelpdata['rows'].length;n++)
            {

                var hid = wxhelpdata['rows'][n]['id'];
                var htitle = wxhelpdata['rows'][n]['title'];
                var hcreate_time = wxhelpdata['rows'][n]['createTime'];
                var htime = dateToStr(new Date(hcreate_time));

                var tmep_html = "<tr class=\"knowledgeItem"+hid+"\">";
                tmep_html+="<td class=\"am-text-middle\">"+hid+"</td>";
                tmep_html+=" <td class=\"am-text-middle\">";
                tmep_html+="<a id=\"imagehref"+hid+"\" href=\"\"\n" +
                    "title=\"点击查看大图\" target=\"_blank\">";//图片处理
                tmep_html+="<img id=\"imageimg"+hid+"\" src=\"\"\n" +
                    "                                                     width=\"50\" height=\"50\" alt=\"小知识图片\">";
                tmep_html+="</a>\n" +
                    "                                        </td>";
                tmep_html+="<td class=\"am-text-middle\">\n" +
                    "                                            <p class=\"item-title\">"+htitle+"</p>\n" +
                    "                                        </td>"
                tmep_html+="<td class=\"am-text-middle\">"+htime+"</td>";
                tmep_html+="<td class=\"am-text-middle\">\n" +
                    "                                            <div class=\"tpl-table-black-operation\">\n" +
                    "                                                <a href=\"/admin/addNewKnowledge.html?id="+hid+"\" >编辑\n" +
                    "                                                </a>\n" +
                    "                                                <a href=\"javascript:deleteItem("+hid+");\" id=\"item-delete\" class=\"item-delete tpl-table-black-operation-del\"\n" +
                    "                                                   data-id=\""+hid+"\">\n" +
                    "                                                    删除\n" +
                    "                                                </a>\n" +
                    "                                            </div>\n" +
                    "                                        </td>\n" +
                    "                                    </tr>";
                $("#knowledgeList").append(tmep_html);

                getKnowledgeImage(hid,callbackImage);
                addImage(hid);
            }
            var allnum = parseInt(wxhelpdata['total']);
            var pageallnum = parseInt(Math.ceil(allnum/10));
            pagenum = parseInt(pagenum);

            var pagehtml = "<div class=\"am-fr\">\n" +
                "                            <ul class=\"pagination\">";
            if(pagenum==1){
                pagehtml+="<li class=\"disabled\">\n" +
                    "                                    <span>«</span>\n" +
                    "                                </li>\n" +
                    "                                <li class=\"active\">\n" +
                    "                                    <span>1</span>\n" +
                    "                                </li>";
            }
            else if(pagenum<=5){
                pagehtml+="<li><a href=\"/admin/knowledge.html?pagenum="+(pagenum-1)+"\""+">«</a>\n" +
                    "                                </li>";
                for(var i=1;i<pagenum;i++){
                    pagehtml+="<li><a href=\"/admin/knowledge.html?pagenum="+i+"\""+">"+i+"</a>\n" +
                        "                                </li>";
                }
                pagehtml+="<li class=\"active\">\n" +
                    "                                    <span>"+pagenum+"</span>\n" +
                    "                                </li>";
            }
            else{
                pagehtml+="<li><a href=\"/admin/knowledge.html?pagenum="+(pagenum-1)+"\""+">«</a>\n" +
                    "                                </li>";
                pagehtml+="<li><a href=\"/admin/knowledge.html?pagenum=1\""+">1</a>\n" +
                    "                                </li>";
                pagehtml+="<li class=\"disabled\"><span>...</span>\n" +
                    "                                </li>";
                for(var i=pagenum-3;i<pagenum;i++){
                    pagehtml+="<li><a href=\"/admin/knowledge.html?pagenum="+i+"\""+">"+i+"</a>\n" +
                        "                                </li>";
                }
                pagehtml+="<li class=\"active\">\n" +
                    "                                    <span>"+pagenum+"</span>\n" +
                    "                                </li>";
            }

            if(pagenum == pageallnum){
                pagehtml+="<li class=\"disabled\">\n" +
                    "                                    <span>»</span>\n" +
                    "                                </li>";
            }
            else if(pageallnum-4<pagenum){

                for(var i=pagenum+1;i<=pageallnum;i++){
                    pagehtml+="<li><a href=\"/admin/knowledge.html?pagenum="+i+"\""+">"+i+"</a>\n" +
                        "                                </li>";
                }
                pagehtml+="<li><a href=\"/admin/knowledge.html?pagenum="+(pagenum+1)+"\""+">»</a>\n" +
                    "                                </li>";

            }
            else{
                for(var i=pagenum+1;i<=pagenum+3;i++){
                    pagehtml+="<li><a href=\"/admin/knowledge.html?pagenum="+i+"\""+">"+i+"</a>\n" +
                        "                                </li>";
                }
                pagehtml+="<li class=\"disabled\"><span>...</span>\n" +
                    "                                </li>";

                pagehtml+="<li><a href=\"/admin/knowledge.html?pagenum="+pageallnum+"\""+">"+pageallnum+"</a>\n" +
                    "                                </li>";
                pagehtml+="<li><a href=\"/admin/knowledge.html?pagenum="+(pagenum+1)+"\""+">»</a>\n" +
                    "                                </li>";
            }
            pagehtml+="</ul>\n" +
                "                        </div>\n" +
                "                        <div class=\"am-fr pagination-total am-margin-right\">\n" +
                "                            <div class=\"am-vertical-align-middle\">总记录："+allnum+"</div>\n" +
                "                        </div>";
            $("#pageitem").append(pagehtml);

        };
        findAllKnowledgeByType(1,pagenum,callbackCreateTimeDESC);

    }





    function deleteItem(itemid) {

        layer.confirm('确定要删除所有内容吗？'
            , {title: '友情提示'}
            , function (index) {
                deleteKnowledge(itemid);
                $(".knowledgeItem"+itemid).remove();
                layer.close(index);
            },function ()
            {
                layer.close();
            });




    }

    function dateToStr(datetime){

        var year = datetime.getFullYear();
        var month = datetime.getMonth()+1;//js从0开始取
        var date = datetime.getDate();
        var hour = datetime.getHours();
        var minutes = datetime.getMinutes();
        var second = datetime.getSeconds();

        if(month<10){
            month = "0" + month;
        }
        if(date<10){
            date = "0" + date;
        }
        if(hour <10){
            hour = "0" + hour;
        }
        if(minutes <10){
            minutes = "0" + minutes;
        }
        if(second <10){
            second = "0" + second ;
        }

        var time = year+"-"+month+"-"+date+" "+hour+":"+minutes+":"+second; //2009-06-12 17:18:05
        //alert(time);
        return time;
    }

</script>
<script src="Scripts/layer.js"></script>
<script src="Scripts/jquery.form.min.js"></script>
<script src="Scripts/amazeui.min.js"></script>
<script src="Scripts/webuploader.html5only.js"></script>
<script src="Scripts/art-template.js"></script>
<script src="Scripts/app.js"></script>
<script src="Scripts/file.library.js"></script>
</body>

</html>